<template>

    <fileUploader></fileUploader>

    <!--div class="drop"></div-->
    <!--https://9elements.github.io/fancy-border-radius/-->
    <div class="drop-zone"></div>


</template>

<style scoped>
.drop{
    width: 150px;
    height: 150px;
  position: fixed;
  z-index: 9;
    background: transparent;
  cursor: move;
    /*border-radius: 56% 44% 63% 37% / 35% 47% 53% 65% ;*/
    border-radius: 20%;
    box-shadow: inset 10px 10px 10px rgba(0, 0, 0, 0.05),
        15px 25px 10px rgba(0, 0, 0, 0.1),
        15px 20px 20px rgba(0, 0, 0, 0.05),
        inset -10px -10px 15px rgba(255, 255, 255, 0.9);
}
.drop-zone {
  position: fixed;
  float: left;
  width: 110px;
  height: 110px;
  z-index: 10;
  cursor: move;
  border: dashed 4px #88888888;
  border-radius: 20px;
  background-color: #ddd0;
}
</style>

<script setup>
import { ref, onMounted } from 'vue'
import { getCurrentInstance } from 'vue'
import { useRouter } from 'vue-router';
import { useStore } from 'vuex'
import { key } from '../store'
import fileUploader from "./components/FileUploader.vue";

const app = getCurrentInstance()
const router = useRouter();
const store = useStore(key)
const serverurl = app.appContext.config.globalProperties.$serverurl



function dragElement(elmnt) {
  var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
  if (document.getElementById(elmnt.id + "header")) {
    // if present, the header is where you move the DIV from:
    document.getElementById(elmnt.id + "header").onmousedown = dragMouseDown;
  } else {
    // otherwise, move the DIV from anywhere inside the DIV:
    elmnt.onmousedown = dragMouseDown;
  }

  function dragMouseDown(e) {
    e = e || window.event;
    e.preventDefault();
    // get the mouse cursor position at startup:
    pos3 = e.clientX;
    pos4 = e.clientY;
    document.onmouseup = closeDragElement;
    // call a function whenever the cursor moves:
    document.onmousemove = elementDrag;
  }

  function elementDrag(e) {
    e = e || window.event;
    e.preventDefault();
    // calculate the new cursor position:
    pos1 = pos3 - e.clientX;
    pos2 = pos4 - e.clientY;
    pos3 = e.clientX;
    pos4 = e.clientY;
    // set the element's new position:
    elmnt.style.top = (elmnt.offsetTop - pos2) + "px";
    elmnt.style.left = (elmnt.offsetLeft - pos1) + "px";
  }

  function closeDragElement() {
    // stop moving when mouse button is released:
    document.onmouseup = null;
    document.onmousemove = null;
  }
}


onMounted(() => {
  
    let formData = new FormData()
    formData.append('token', store.state.token)
    fetch(serverurl + 'validate_token', { method: 'POST', body: formData})
        .then((response) => response.json())
        .then((response_result) => {

            let { result } = response_result
            if (result == true){
                //this.login_failure = true
            } else {
                router.push({path: "/login" });
            }
        })

        dragElement(document.getElementsByClassName("drop-zone")[0]);


    })

</script>